/*
 * @Description: 
 * @FilePath: /STM32/USER/bsp/dma.h
 * @Author: Wei Zhou
 * @Github: https://github.com/zromyk
 * @Date: 2021-04-28 15:25:19
 * @LastEditors: Wei Zhou
 * @LastEditTime: 2021-04-28 15:25:19
 * @Copyright: Copyright  2017 muyiro. All rights reserved.
 */
 
#ifndef DMA_INIT_H
#define DMA_INIT_H

#include "my_include.h"

/*
| APB1 (168MHz)  | APB2 (84MHz)  | AHB1 (168MHz)  | AHB2 (168MHz)  |
| -------------- | ------------- | -------------- | -------------- |
|                |               | DMA1           |                |
|                |               | DMA2           |                |
|                |               | DMA2D          |                |
*/

typedef struct {
    DMA_TypeDef         *DMAx;
    uint32_t            RCC_Periph_DMA;

    DMA_Stream_TypeDef  *tx_stream;
    uint32_t            tx_channel;
    IRQn_Type           tx_IRQn;
    uint32_t            tx_FLAG_TCIF;

    DMA_Stream_TypeDef  *rx_stream;
    uint32_t            rx_channel;
    IRQn_Type           rx_IRQn;
    uint32_t            rx_FLAG_TCIF;
} DMA_Dev;

/**
 * @brief  DMA Tx initialize.
 * @param  *dma:        point to a DMA_Dev.
 * @param  DR_addr:     peripheral addr.
 * @param  *tx_buf:     point to a send buffer.
 * @param  tx_buf_size: size of send buffer.
 * @retval None
 */
void dma_tx_init(DMA_Dev *dma, uint32_t DR_addr, uint8_t *tx_buf, uint32_t tx_buf_size);

/**
 * @brief  DMA Rx initialize.
 * @param  *dma:        point to a DMA_Dev.
 * @param  DR_addr:     peripheral addr.
 * @param  *rx_buf:     point to a receive buffer.
 * @param  rx_buf_size: size of receive buffer.
 * @retval None
 */
void dma_rx_init(DMA_Dev *dma, uint32_t DR_addr, uint8_t *rx_buf, uint32_t rx_buf_size);

#endif /* DMA_INIT_H */
